package cn.tedu;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Demo04 {
    public static void main(String[] args) {
        //获取连接 如果括号内报错 alt+回车 set language level to 7
        try (Connection conn = DBUtils.getConn()){
            //创建执行SQL语句的对象
            Statement s = conn.createStatement();
            //3. 执行SQL语句 返回值为结果集对象 里面装着查询回来的结果
            ResultSet rs = s.executeQuery("select name, job,sal from emp");
            //4.遍历结果 next下一个,让游标下游,返回值表示是否有下一条数据
            while (rs.next()) {
                String name = rs.getString(1);
                System.out.println(name);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
